//
//  BK_My_Order_CollectionViewCell.m
//  bestkeep
//
//  Created by TOPTEAM on 2017/2/20.
//  Copyright © 2017年 utouu. All rights reserved.
//

#import "BK_My_Order_CollectionViewCell.h"
#import "BK_OD_Tool.h"
#import "CacheImage.h"
#import "BK_OD_Color.h"


@implementation BK_My_Order_CollectionViewCell
-(void)fillData:(id)data{
    
}
@end
@implementation BK_My_Order_DetaiCell
-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        [self initView];
        
    }
    
    return self;
    
    
}
-(void)initView{
    
    /**
     * 背景View---白色
     */
    _view_back =[[UIView alloc]init];
    _view_back.backgroundColor=[UIColor whiteColor];
    [self addSubview:_view_back];
    [_view_back mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top).offset(0);
        make.left.equalTo(self.mas_left).offset(0);
        make.width.mas_equalTo(@(ScreenWidth));
        make.bottom.equalTo(self.mas_bottom);
    }];
    
    /**
     * 背景View---灰色
     */
    _view_center=[[UIView alloc]init];
    _view_center.backgroundColor=kOrderLightGrey2;
    [_view_back addSubview:_view_center];
    [_view_center mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.mas_top).offset(0);
        make.left.equalTo(self.mas_left).offset(0);
        make.width.mas_equalTo(@(ScreenWidth));
        make.bottom.equalTo(self.mas_bottom).offset(-5);
    }];
    
    /**
     *  订单商品图片
     */
    _ImgV_goods = [UIImageView new];
    _ImgV_goods.backgroundColor = [UIColor whiteColor];
//    _ImgV_goods.layer.borderColor = RGB(221, 221, 221).CGColor;
//    _ImgV_goods.layer.borderWidth = 0.6;
    _ImgV_goods.contentMode = UIViewContentModeScaleToFill;
    [_view_center addSubview:_ImgV_goods];
    [_ImgV_goods mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_view_center.mas_top).offset(7.5);
        make.left.mas_equalTo(_view_center.mas_left).offset(ApplicationBackGauge);
        make.width.mas_equalTo(@(WIDTH_GOODSIMGV));
        make.height.mas_equalTo(@(WIDTH_GOODSIMGV));
    }];
    
    
    
    
    
    
    
    /**
     *  商品名称
     */
    _lab_goodsName = [UILabel new];//商品名称
    _lab_goodsName.textColor = kOrderBlack1;
    _lab_goodsName.font =[UIFont systemFontOfSize:14];
    //自动折行设置
    [_lab_goodsName setLineBreakMode:NSLineBreakByWordWrapping];
    _lab_goodsName.numberOfLines = 2;
    _lab_goodsName.text = @" --- ";
    _lab_goodsName.backgroundColor = [UIColor clearColor];
    [_view_center addSubview:_lab_goodsName];
    [_lab_goodsName mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_ImgV_goods.mas_top);
        make.left.mas_equalTo(_ImgV_goods.mas_right).offset(ApplicationBackGauge);
        make.right.mas_equalTo(_view_center.mas_right).offset(-100);
    }];
    
    
    /*
     * 预售
     */
    _imgV_YuShou_Icon = [[UIImageView alloc] init];
    [_imgV_YuShou_Icon setContentMode:UIViewContentModeScaleAspectFit];
    _imgV_YuShou_Icon.image = [UIImage imageNamed:@"icon_time_nor"];
    [_view_center addSubview:_imgV_YuShou_Icon];
    
    
    /*
     * 预售
     */
    [_imgV_YuShou_Icon mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(_lab_goodsName.mas_left);
        make.top.mas_equalTo(_lab_goodsName.mas_top).offset(0.8f);
        make.height.mas_equalTo(14);
        make.width.mas_equalTo(132.0f/45.0f*14);
    }];
    
    /**
     *  属性
     */
    _lab_goodsParameter = [UILabel new];
    _lab_goodsParameter.textColor = kOrderLightGrey1;
    _lab_goodsParameter.font = Font12;
    _lab_goodsParameter.numberOfLines=1;
    _lab_goodsParameter.text = @" ---ss ";
    _lab_goodsParameter.backgroundColor = [UIColor clearColor];
    [_view_center addSubview:_lab_goodsParameter];
    [_lab_goodsParameter mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_lab_goodsName.mas_bottom).offset(3);
        make.left.mas_equalTo(_ImgV_goods.mas_right).offset(10);
        make.right.mas_equalTo(_lab_goodsName.mas_right).offset(0);
    }];
    
    /**
     *  发货日期
     */
    _lab_goods_FaHuo = [UILabel new];
    _lab_goods_FaHuo.textColor = kOrderLightGrey1;
    _lab_goods_FaHuo.font = [UIFont systemFontOfSize:12];
    _lab_goods_FaHuo.numberOfLines=1;
    _lab_goods_FaHuo.text = @"加载中....";
    _lab_goods_FaHuo.backgroundColor = [UIColor clearColor];
    [_view_center addSubview:_lab_goods_FaHuo];
    [_lab_goods_FaHuo mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_lab_goodsParameter.mas_bottom).offset(2);
        make.left.mas_equalTo(_ImgV_goods.mas_right).offset(10);
        make.right.mas_equalTo(self.mas_right).offset(-30);
    }];
    _lab_goods_FaHuo.hidden=YES;
    
    /**
     *  交易完成图片
     */
    _imgV_goodsFinish = [UIImageView new];
    _imgV_goodsFinish.backgroundColor = [UIColor clearColor];
    _imgV_goodsFinish.image = [UIImage imageNamed:@"Group Copy 20"];
    _imgV_goodsFinish.hidden = YES;
    [_view_center addSubview:_imgV_goodsFinish];
    
    [_imgV_goodsFinish mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_view_center.mas_top).offset(0);
        make.right.mas_equalTo(_view_center.mas_right).offset(-40);
        make.width.mas_equalTo(@(50));
        make.height.mas_equalTo(@(50));
    }];
    
    /**
     *  下划线
     */
    _view_line = [UILabel new];
    _view_line.backgroundColor = [UIColor grayColor];
    _view_line.alpha = 0.5;
    [_view_center addSubview:_view_line];
    [_view_line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(_view_center.mas_bottom).offset(0);
        make.right.mas_equalTo(_view_center.mas_right).offset(0);
        make.left.mas_equalTo(_view_center.mas_left).offset(0);
        make.height.mas_equalTo(@(0.5));
    }];
    
    /**
     *  实付款
     */
    _lab_Money= [UILabel new];
    _lab_Money.textColor = kOrderBlack1;
    _lab_Money.font = [UIFont boldSystemFontOfSize:14];
    _lab_Money.numberOfLines=1;
    _lab_Money.text = @"¥0.00";
    _lab_Money.textAlignment=NSTextAlignmentRight;
    _lab_Money.backgroundColor = [UIColor clearColor];
    [_view_center addSubview:_lab_Money];
    [_lab_Money mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_lab_goodsName.mas_top);
        make.right.mas_equalTo(_view_center.mas_right).offset(-ApplicationBackGauge);
        make.width.equalTo(@(200));
    }];
    
    
    /**
     *  数量
     */
    _lab_Mont= [UILabel new];
    _lab_Mont.textColor = kOrderLightGrey1;
    _lab_Mont.font = Font12;
    _lab_Mont.numberOfLines=1;
    _lab_Mont.text = @"x1";
    _lab_Mont.textAlignment=NSTextAlignmentRight;
    _lab_Mont.backgroundColor = [UIColor clearColor];
    [_view_center addSubview:_lab_Mont];
    [_lab_Mont mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_lab_Money.mas_bottom).offset(0);
        make.right.mas_equalTo(_view_center.mas_right).offset(-ApplicationBackGauge);
        make.height.equalTo(@(30));
        make.width.equalTo(@(200));
    }];
    
    _view_line.hidden=YES;
}

-(void)fillData:(id)data{
    BK_My_Order_CellModel *cell = data;
    BK_My_Order_rows_itemList_Model *centerModel = cell.DetailModel;
    
    /*
     * 订单完成图标暂时取消
     */
    _imgV_goodsFinish.hidden=YES;
    
    /*
     * 实付款
     */
    _lab_Money.text =[NSString stringWithFormat:@"¥ %.2f",[centerModel.member_price floatValue]];
    
    
    /*
     * 数量
     */
    _lab_Mont.text=[NSString stringWithFormat:@"x%@",centerModel.amount];
    
    
    [_ImgV_goods load:centerModel.goods_img];
    
    
    _lab_goodsParameter.text = centerModel.sale_property;
//    _lab_goodsName.text = centerModel.goods_name;
    
    
    
    
    /*
     * 预购判断
     */
    if ( [[NSString stringWithFormat:@"%@", centerModel.thNormalType ] isEqualToString:@"1"]) {
        _imgV_YuShou_Icon.hidden = NO;
        _lab_goodsName.text = [NSString stringWithFormat:@"             %@",centerModel.goods_name];            //物品详情介绍
    }else {
        _lab_goodsName.text = centerModel.goods_name;            //物品详情介绍
        _imgV_YuShou_Icon.hidden = YES;
    }
    
    
    
    /*
     * 预计发货日期
     */
    if (centerModel.plan_deliver_date&&centerModel.plan_deliver_date.length>1) {
        if ([cell.model_Order_rows.status isEqualToString:@"01"]||[cell.model_Order_rows.status isEqualToString:@"02"]) {
            _lab_goods_FaHuo.hidden=NO;
            _lab_goods_FaHuo.text=centerModel.plan_deliver_date;
        }else{
            _lab_goods_FaHuo.hidden=YES;
        }
    }else{
        _lab_goods_FaHuo.hidden=YES;
    }
    CGFloat Width_Money=[BK_My_Order_DetaiCell getWidthWithTitle:[NSString stringWithFormat:@"¥ %.2f",[centerModel.member_price floatValue]] font:15.0];
    CGFloat Width_Name=[BK_My_Order_DetaiCell getWidthWithTitle:centerModel.goods_name font:15.0];
    CGFloat Width=ScreenWidth-Width_Money-WIDTH_GOODSIMGV-10-10-10;
    
    if (Width<Width_Name+10) {
        CGFloat right_Width_Money;
        if (Width_Money>90) {
            right_Width_Money=Width_Money;
            [_lab_goodsName mas_remakeConstraints:^(MASConstraintMaker *make) {
                make.top.mas_equalTo(_ImgV_goods.mas_top);
                make.left.mas_equalTo(_ImgV_goods.mas_right).offset(10);
                make.right.mas_equalTo(_view_center.mas_right).offset(-Width_Money-10);
            }];
        }else{
        }
    }
    
}
/**
 *   获取字符宽度
 */
+ (CGFloat)getWidthWithTitle:(NSString *)title font:(CGFloat )font {
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 1000, 0)];
    label.text = title;
    label.font = [UIFont systemFontOfSize:font];
    [label sizeToFit];
    return label.frame.size.width;
}

@end





















